﻿using MediatR;
using PublicClass;
using S.Eartag.Domain;
using S.Eartag.Domain.Model;
using S.Eartag.Infrastructure.Interface;
using S.Eartag.Read.API.Application.Command.SheepFileConditionCommand;

namespace S.Eartag.Read.API.Application.CommandHandlers.SheepFileConditionCommandHandler
{
    public class SheepFileConditionarchivesCommandHandler : IRequestHandler<SheepFileConditionarchivesCommand, List<ArchivesDTO>>
    {
        private readonly ISheepFileRepository sheepFileRepository;

        public SheepFileConditionarchivesCommandHandler(ISheepFileRepository sheepFileRepository)
        {
            this.sheepFileRepository = sheepFileRepository;
        }

        public async Task<List<ArchivesDTO> > Handle(SheepFileConditionarchivesCommand request, CancellationToken cancellationToken)
        {
            var res =await sheepFileRepository.All();

            var  archives = new List<ArchivesDTO>();
            foreach (var item in res)
            {
                archives.Add(new ArchivesDTO
                {
                    SheepType = item.sheepType.ToString(),
                    Breed = item.breed.ToString(),
                    sex = item.sex,
                    card=item.EarNumber,
                    ReproductiveState=item.reproductiveState.ToString(),
                });
            };  
            return  archives;
        }
    }
}
